
import CryptoJS from 'crypto-js';
let Crypt = {

/*AES加密*/
    Encrypt : (dataStr, authTokenKey, authTokenIv) => {
        let encrypted = CryptoJS.AES.encrypt(dataStr, CryptoJS.enc.Latin1.parse(authTokenKey), {
            iv: CryptoJS.enc.Latin1.parse(authTokenIv),
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.Pkcs7
        });
        return encrypted.toString();
    },
    
/*AES解密*/
    Decrypt : (data, authTokenKey, authTokenIv) => {
        let data2 = data.replace(/\n/gm, "");
        let decrypted = CryptoJS.AES.decrypt(data2, CryptoJS.enc.Latin1.parse(authTokenKey), {
            iv: CryptoJS.enc.Latin1.parse(authTokenIv),
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.Pkcs7
        });
        return decrypted.toString(CryptoJS.enc.Utf8);
    }
}

export default Crypt;